package com.feng.rabbitmq.seven;

import com.feng.rabbitmq.utiils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * 消费者1
 */
public class ReceiveLogsTopic01 {

    //交换机的名称
    public static final String EXCHANGE_NAME = "topic_logs";

    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"topic");
        //声明队列
        String queue_name = "Q1";
        channel.queueDeclare(queue_name,false,false,false,null);
        //队列和交换机绑定
        channel.queueBind(queue_name,EXCHANGE_NAME,"*.orange.*");
        System.out.println("ReceiveLogsTopic01等待接收消息");
        //接收消息
        DeliverCallback deliverCallback = (consumerTag,message) -> {
            System.out.println(new String(message.getBody()));
            System.out.println("队列名称是："+queue_name+" 绑定键："+message.getEnvelope().getRoutingKey());
        };
        channel.basicConsume(queue_name,true,deliverCallback,consumerTag -> {});
    }
}
